<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title></title>

    <link rel="stylesheet" th:href="@{/res/css/amazeui.min.css}">
    <link rel="stylesheet" th:href="@{/res/css/admin.css}">
    <link rel="stylesheet" th:href="@{/res/css/app.css}">
    <script type="text/javascript" th:src="@{/js/jquery-1.11.3.min.js}"></script>
    <style>
        .admin-main {
            padding-top: 0px;
        }

        #btconfirm{
            position: relative;
            top:0px;
            left:25px;
        }

        #btcancel{
            position: relative;
            top:0px;
            left:75px;
        }
    </style>
</head>

<body>
<div class="am-cf admin-main">
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-g">
                <form class="am-form am-form-horizontal" action="role/addroleSubmit.action" method="post"
                      style="padding-top: 20px;">
                    <div class="am-form-group">
                        <label class="am-u-sm-3 am-form-label">
                            充值金额:
                        </label>
                        <div class="am-u-sm-9">
                            <input id="money" required="" placeholder="请输入充值金额" value="" type="text">
                        </div>
                    </div>

                    <div class="am-form-group">
                        <label class="am-u-sm-3 am-form-label">
                            支付密码:
                        </label>
                        <div class="am-u-sm-9">
                            <input id="pw" required="" placeholder="请输入支付密码" value="" type="password">
                        </div>
                    </div>

                    <div class="am-form-group">
                        <div class="am-u-sm-9 am-u-sm-push-3">
                            <input class="am-btn am-btn-default am-btn-primary" value="确认" type="button" onclick="confirm()" id="btconfirm">
                            <input class="am-btn am-btn-default am-btn-primary" value="取消" type="button" onclick="cancel()" id="btcancel">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    //从url都取wid
    var result=new Object();
    result=getParameter();
    var uid=result["uid"];

    //确认，向管理员提交申请
    function confirm() {
        var money=document.getElementById("money").value;
        var pw=document.getElementById("pw").value;
        if(money==""){
            alert("充值金额不能为空");
        }
        if(pw==""){
            alert("密码不能为空");
        }
        if(money!=""&&pw!=""){
            $.ajax({
                type: 'post',
                url: '/wallet/cashin',
                data: {uid:uid,money:money,pw:pw},
                dataType: 'json',
                success: function (mydata) {
                    if(JSON.stringify(mydata)=="true"){
                        alert("充值申请成功，待审核")
                        parent.location.reload();
                    }
                    else{
                        alert("充值申请失败");
                    }
                },
                error: function () {
                    alert("充值请求失败");
                }
            });
        }
    }

    //取消，返回上一页
    function cancel() {
        close();
    }

    //关闭当前页面
    function close() {
        window.parent.location.reload();
    }

    //解析url传值
    function getParameter() {
        var url=location.search;//获取url?后面的内容
        var result=new Object();
        if(url.indexOf("?")!= -1){
            var str=url.substr(1);
            strs=str.split("&");
            for(var i=0;i<strs.length;i++){
                result[strs[i].split("=")[0]]=decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return result;
    }
</script>
</html>
